package pack0711.com;

import org.w3c.dom.ls.LSOutput;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

public class Tools {

    private static Scanner scan=new Scanner(System.in);
    //获取正确的菜单选项
    public static int getN(int start,int end){
        System.out.println("请选择功能: ");
        while(true){
            try {
                int n=scan.nextInt();
                if(n<start||n>end) {
                    System.out.println("抱歉,没有此项功能,请重新选择");
                    continue;
                }
                return n;
            }catch(Exception e){
                System.out.println("必须输入整数,请重新输入");
                scan=new Scanner(System.in);
            }
        }
    }
    //创建新用户的ID
    public static String getNewId(){
       return new SimpleDateFormat("hhmmss").format(new Date());
    }

    public static int getMoney() {
        while(true){
            try{
                int money =scan.nextInt();
                if(money<0){
                    System.out.println("金额不得小于0,请重新输入: ");
                    continue;
                }
                return money;
            }catch(Exception e){
                System.out.println("金钱只能是数字,请重新输入: ");
                scan=new Scanner(System.in);
            }
        }
    }

    //获取当前的时间格式化
    public static String getCurrentDate() {
        return new SimpleDateFormat("YYYY年MM月dd日 hh:mm:ss").format(new Date());
    }

    //判断给定的用户账号是否存在
    public static User exists(List<User> list, String id) {
        for(User user:list){
            if(user.getId().equals(id))
                return user;
        }
        return null;
    }



}
